package com.exprecards.common.util;

import java.util.Calendar;

import com.mail.notification.Recipient;
import com.mail.notification.mail.MailNotification;
import com.mail.notification.mail.MailNotificationSender;

public class MailSenderUtils {

	
    private static MailSenderUtils instance;	
	
	
	public static synchronized MailSenderUtils getInstance() {
		if( instance == null ) {
			instance = new MailSenderUtils();
		}
		
		return instance;
	}
	
	public MailSenderUtils(){
		
		
	}
	
	
	/*public boolean sendMail(String destinatario, String cc, String bcc, String sender, ){
		boolean resultado = false;
		
		
		
		
		return resultado;
	}*/
	
	
   public boolean enviarNotificacionPedidoObservacion(String idPedido, String estado,String observacion,String usuario,String fecha){
		
		
		MailNotificationSender sender = new MailNotificationSender ();
		
		MailNotification mail = new MailNotification ();
		
		String msgHtml = "  <html lang=\"en\">   <head>     <meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\">     <title>       Industrial     </title> 	   </head>   <BODY style=\"margin: 0; padding: 0; background: #080708 url('http://www.exprecards.net/EXPRECARDS/resources/img/bg_email.png');\" bgcolor=\"#080708\">      <table width=\"400\" border=\"0\" align=\"center\" style=\"background:#000\">   <tr>     <td style=\"border-bottom:solid 1px #999999;padding:0; margin:0\"><img src=\"http://www.exprecards.net/EXPRECARDS/resources/img/logo.jpg\" alt=\"\" width=\"400\" height=\"86\" border=\"0\" style=\"border:0\"></td>   </tr>   <tr>     <td>&nbsp;</td>   </tr>   <tr>     <td>     <p style=\"color:#ffd801; font-weight: normal; margin: 0; padding-left: 12px; line-height: 20px; font-size: 14px;font-family: Verdana, Geneva, sans-serif;background:url(http://www.exprecards.net/EXPRECARDS/resources/img/bg_bullet.jpg) no-repeat 3px 5px \">TITULO_MSG</p>          <p style=\"color:#fff; font-weight: normal; margin: 0; padding: 10px; line-height: 20px; font-size: 12px;font-family: Verdana, Geneva, sans-serif;; \"> 									BODY_MSG  	</p></td>   </tr>   <tr>     <td>&nbsp;</td>   </tr>   <tr>     <td align=\"center\" style=\"padding: 5px 0 10px; font-size: 11px; color:#7d7a7a; margin: 0; line-height: 1.2;font-family: Helvetica, Arial, sans-serif;\" valign=\"top\"><p style=\"font-size: 11px; color:#7d7a7a; margin: 0; padding: 0;font-family: Helvetica, Arial, sans-serif; \">Exprecards C.I. S.A.S. Derechos Reservados</p></td>   </tr>   </table>   </BODY> </html>";
		mail.setSender("mailsenderexprecards@gmail.com", "EXPRECARDS C.I. SAS");
		mail.setSubject("SISTEMA DE PEDIDOS - OBSERVACIONES PEDIDO ["+idPedido+"]");
		
		//Mensaje
		msgHtml = msgHtml.replaceAll("TITULO_MSG", "Se registraron observaciones al pedido ["+idPedido+"] en el estado "+estado);
		
		String body = "El usuario ["+usuario+"] en la fecha ["+fecha+"] ingres&oacute; la siguiente observaci&oacute;n <br/> '"+observacion+"'" ;
		
		body+="<br/><br/> <a href='http://www.exprecards.net'> Ingresar al sistema </a>";
		
		msgHtml = msgHtml.replaceAll("BODY_MSG", body);
		
		mail.setText(msgHtml);
		mail.setHtmlMail(true);
		
		//Miestras produccion
		mail.addCC(new Recipient ("javima4@gmail.com", "Recipient"));
		
		mail.addRecipient(new Recipient ("servicioalcliente@exprecards.com", "Recipient"));
		mail.addCC(new Recipient ("calidad@exprecards.com", "Recipient"));
		//Miestras produccion
		mail.addCC(new Recipient ("javima4@gmail.com", "Recipient"));
				
		sender.send(mail);
		
		return false;
	}
   
   
   
   public boolean enviarNotificacionAnularPedido(String idPedido,String observacion,String usuario,String fecha,String mailAdminEmpresa){
		
		
		MailNotificationSender sender = new MailNotificationSender ();
		
		MailNotification mail = new MailNotification ();
		
		String msgHtml = "  <html lang=\"en\">   <head>     <meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\">     <title>       Industrial     </title> 	   </head>   <BODY style=\"margin: 0; padding: 0; background: #080708 url('http://www.exprecards.net/EXPRECARDS/resources/img/bg_email.png');\" bgcolor=\"#080708\">      <table width=\"400\" border=\"0\" align=\"center\" style=\"background:#000\">   <tr>     <td style=\"border-bottom:solid 1px #999999;padding:0; margin:0\"><img src=\"http://www.exprecards.net/EXPRECARDS/resources/img/logo.jpg\" alt=\"\" width=\"400\" height=\"86\" border=\"0\" style=\"border:0\"></td>   </tr>   <tr>     <td>&nbsp;</td>   </tr>   <tr>     <td>     <p style=\"color:#ffd801; font-weight: normal; margin: 0; padding-left: 12px; line-height: 20px; font-size: 14px;font-family: Verdana, Geneva, sans-serif;background:url(http://www.exprecards.net/EXPRECARDS/resources/img/bg_bullet.jpg) no-repeat 3px 5px \">TITULO_MSG</p>          <p style=\"color:#fff; font-weight: normal; margin: 0; padding: 10px; line-height: 20px; font-size: 12px;font-family: Verdana, Geneva, sans-serif;; \"> 									BODY_MSG  	</p></td>   </tr>   <tr>     <td>&nbsp;</td>   </tr>   <tr>     <td align=\"center\" style=\"padding: 5px 0 10px; font-size: 11px; color:#7d7a7a; margin: 0; line-height: 1.2;font-family: Helvetica, Arial, sans-serif;\" valign=\"top\"><p style=\"font-size: 11px; color:#7d7a7a; margin: 0; padding: 0;font-family: Helvetica, Arial, sans-serif; \">Exprecards C.I. S.A.S. Derechos Reservados</p></td>   </tr>   </table>   </BODY> </html>";
		mail.setSender("mailsenderexprecards@gmail.com", "EXPRECARDS C.I. SAS");
		mail.setSubject("SISTEMA DE PEDIDOS - ANULADO PEDIDO ["+idPedido+"]");
		
		//Mensaje
		msgHtml = msgHtml.replaceAll("TITULO_MSG", "Se anul&oacute; el pedido ["+idPedido+"]");
		
		String body = "El usuario ["+usuario+"] en la fecha ["+fecha+"] anul&oacute; el pedido con la siguiente observaci&oacute;n <br/> '"+observacion+"'" ;
		
		body+="<br/><br/> <a href='http://www.exprecards.net'> Ingresar al sistema </a>";
		
		msgHtml = msgHtml.replaceAll("BODY_MSG", body);
		
		mail.setText(msgHtml);
		mail.setHtmlMail(true);
		
		//mail.addRecipient(new Recipient ("javima4@gmail.com", "Recipient"));
		
		mail.addRecipient(new Recipient ("servicioalcliente@exprecards.com", "Recipient"));
		mail.addCC(new Recipient ("calidad@exprecards.com", "Recipient"));
		mail.addCC(new Recipient (mailAdminEmpresa, "Recipient"));
		//Miestras produccion
		mail.addCC(new Recipient ("javima4@gmail.com", "Recipient"));
		
		sender.send(mail);
		
		return false;
	}
   
   
   
   
   public boolean enviarNotificacionStockPorAcabar(String idProducto,String nombreProducto,String cantidadDisponible,String fecha,String mailAdminEmpresa){
		
		
		MailNotificationSender sender = new MailNotificationSender ();
		
		MailNotification mail = new MailNotification ();
		
		String msgHtml = "  <html lang=\"en\">   <head>     <meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\">     <title>       Industrial     </title> 	   </head>   <BODY style=\"margin: 0; padding: 0; background: #080708 url('http://www.exprecards.net/EXPRECARDS/resources/img/bg_email.png');\" bgcolor=\"#080708\">      <table width=\"400\" border=\"0\" align=\"center\" style=\"background:#000\">   <tr>     <td style=\"border-bottom:solid 1px #999999;padding:0; margin:0\"><img src=\"http://www.exprecards.net/EXPRECARDS/resources/img/logo.jpg\" alt=\"\" width=\"400\" height=\"86\" border=\"0\" style=\"border:0\"></td>   </tr>   <tr>     <td>&nbsp;</td>   </tr>   <tr>     <td>     <p style=\"color:#ffd801; font-weight: normal; margin: 0; padding-left: 12px; line-height: 20px; font-size: 14px;font-family: Verdana, Geneva, sans-serif;background:url(http://www.exprecards.net/EXPRECARDS/resources/img/bg_bullet.jpg) no-repeat 3px 5px \">TITULO_MSG</p>          <p style=\"color:#fff; font-weight: normal; margin: 0; padding: 10px; line-height: 20px; font-size: 12px;font-family: Verdana, Geneva, sans-serif;; \"> 									BODY_MSG  	</p></td>   </tr>   <tr>     <td>&nbsp;</td>   </tr>   <tr>     <td align=\"center\" style=\"padding: 5px 0 10px; font-size: 11px; color:#7d7a7a; margin: 0; line-height: 1.2;font-family: Helvetica, Arial, sans-serif;\" valign=\"top\"><p style=\"font-size: 11px; color:#7d7a7a; margin: 0; padding: 0;font-family: Helvetica, Arial, sans-serif; \">Exprecards C.I. S.A.S. Derechos Reservados</p></td>   </tr>   </table>   </BODY> </html>";
		mail.setSender("mailsenderexprecards@gmail.com", "EXPRECARDS C.I. SAS");
		mail.setSubject("SISTEMA DE PEDIDOS - SE ACABA STOCK PRODUCTO ["+nombreProducto+"]");
		
		//Mensaje
		msgHtml = msgHtml.replaceAll("TITULO_MSG", "Se acaba el stock del producto con c&oacute;digo ["+idProducto+"],  nombre ["+nombreProducto+"]");
		
		String body = "Solo tenemos ["+cantidadDisponible+"] unidades del producto " ;
		
		body+="<br/><br/> <a href='http://www.exprecards.net'> Ingresar al sistema </a>";
		
		msgHtml = msgHtml.replaceAll("BODY_MSG", body);
		
		mail.setText(msgHtml);
		mail.setHtmlMail(true);
		
		//mail.addRecipient(new Recipient ("javima4@gmail.com", "Recipient"));
		
		mail.addRecipient(new Recipient ("servicioalcliente@exprecards.com", "Recipient"));
		mail.addRecipient(new Recipient (mailAdminEmpresa, "Recipient"));
		
		//Miestras produccion
		mail.addCC(new Recipient ("javima4@gmail.com", "Recipient"));
		
		sender.send(mail);
		
		return false;
	}
   
   
   
   public boolean enviarNotificacionPedidoDigitado(String idPedido,String usuario,String fecha,String mailEjecutivoCta,String valor){
		
		
		MailNotificationSender sender = new MailNotificationSender ();
		
		MailNotification mail = new MailNotification ();
		
		String msgHtml = "  <html lang=\"en\">   <head>     <meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\">     <title>       Industrial     </title> 	   </head>   <BODY style=\"margin: 0; padding: 0; background: #080708 url('http://www.exprecards.net/EXPRECARDS/resources/img/bg_email.png');\" bgcolor=\"#080708\">      <table width=\"400\" border=\"0\" align=\"center\" style=\"background:#000\">   <tr>     <td style=\"border-bottom:solid 1px #999999;padding:0; margin:0\"><img src=\"http://www.exprecards.net/EXPRECARDS/resources/img/logo.jpg\" alt=\"\" width=\"400\" height=\"86\" border=\"0\" style=\"border:0\"></td>   </tr>   <tr>     <td>&nbsp;</td>   </tr>   <tr>     <td>     <p style=\"color:#ffd801; font-weight: normal; margin: 0; padding-left: 12px; line-height: 20px; font-size: 14px;font-family: Verdana, Geneva, sans-serif;background:url(http://www.exprecards.net/EXPRECARDS/resources/img/bg_bullet.jpg) no-repeat 3px 5px \">TITULO_MSG</p>          <p style=\"color:#fff; font-weight: normal; margin: 0; padding: 10px; line-height: 20px; font-size: 12px;font-family: Verdana, Geneva, sans-serif;; \"> 									BODY_MSG  	</p></td>   </tr>   <tr>     <td>&nbsp;</td>   </tr>   <tr>     <td align=\"center\" style=\"padding: 5px 0 10px; font-size: 11px; color:#7d7a7a; margin: 0; line-height: 1.2;font-family: Helvetica, Arial, sans-serif;\" valign=\"top\"><p style=\"font-size: 11px; color:#7d7a7a; margin: 0; padding: 0;font-family: Helvetica, Arial, sans-serif; \">Exprecards C.I. S.A.S. Derechos Reservados</p></td>   </tr>   </table>   </BODY> </html>";
		mail.setSender("mailsenderexprecards@gmail.com", "EXPRECARDS C.I. SAS");
		mail.setSubject("SISTEMA DE PEDIDOS - PEDIDO DIGITADO ["+idPedido+"]");
		
		//Mensaje
		msgHtml = msgHtml.replaceAll("TITULO_MSG", "Se ha digitado el pedido ["+idPedido+"]");
		
		String body = "El usuario ["+usuario+"] en la fecha ["+fecha+"] ha digitado el pedido con un valor total de [\\$ "+valor+"]" ;
		
		body+="<br/><br/> <a href='http://www.exprecards.net'> Ingresar al sistema </a>";
		
		msgHtml = msgHtml.replaceAll("BODY_MSG", body);
		
		mail.setText(msgHtml);
		mail.setHtmlMail(true);
		
		//mail.addRecipient(new Recipient ("javima4@gmail.com", "Recipient"));
		
		mail.addRecipient(new Recipient ("servicioalcliente@exprecards.com", "Recipient"));
		mail.addRecipient(new Recipient (mailEjecutivoCta, "Recipient"));
		
		//Miestras produccion
		mail.addCC(new Recipient ("javima4@gmail.com", "Recipient"));
		
		sender.send(mail);
		
		return false;
	}
   
   
   public boolean enviarNotificacionContactenos(String empresa, String direccion,String nit,String personaContacto,String email,String telefonoFijo, String telefonoCelular,String message){
		
		
		MailNotificationSender sender = new MailNotificationSender ();
		
		MailNotification mail = new MailNotification ();
		
		String msgHtml = "  <html lang=\"en\">   <head>     <meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\">     <title>       Industrial     </title> 	   </head>   <BODY style=\"margin: 0; padding: 0; background: #080708 url('http://www.exprecards.net/EXPRECARDS/resources/img/bg_email.png');\" bgcolor=\"#080708\">      <table width=\"400\" border=\"0\" align=\"center\" style=\"background:#000\">   <tr>     <td style=\"border-bottom:solid 1px #999999;padding:0; margin:0\"><img src=\"http://www.exprecards.net/EXPRECARDS/resources/img/logo.jpg\" alt=\"\" width=\"400\" height=\"86\" border=\"0\" style=\"border:0\"></td>   </tr>   <tr>     <td>&nbsp;</td>   </tr>   <tr>     <td>     <p style=\"color:#ffd801; font-weight: normal; margin: 0; padding-left: 12px; line-height: 20px; font-size: 14px;font-family: Verdana, Geneva, sans-serif;background:url(http://www.exprecards.net/EXPRECARDS/resources/img/bg_bullet.jpg) no-repeat 3px 5px \">TITULO_MSG</p>          <p style=\"color:#fff; font-weight: normal; margin: 0; padding: 10px; line-height: 20px; font-size: 12px;font-family: Verdana, Geneva, sans-serif;; \"> 									BODY_MSG  	</p></td>   </tr>   <tr>     <td>&nbsp;</td>   </tr>   <tr>     <td align=\"center\" style=\"padding: 5px 0 10px; font-size: 11px; color:#7d7a7a; margin: 0; line-height: 1.2;font-family: Helvetica, Arial, sans-serif;\" valign=\"top\"><p style=\"font-size: 11px; color:#7d7a7a; margin: 0; padding: 0;font-family: Helvetica, Arial, sans-serif; \">Exprecards C.I. S.A.S. Derechos Reservados</p></td>   </tr>   </table>   </BODY> </html>";
		mail.setSender("mailsenderexprecards@gmail.com", "EXPRECARDS C.I. SAS");
		mail.setSubject("EXPRECARDS C.I. SAS - CONTACTENOS EMPRESA ["+empresa+"]");
		
		//Mensaje
		msgHtml = msgHtml.replaceAll("TITULO_MSG", "Se solicit&oacute; informaci&oacute;n de contacto de la empresa ["+empresa+"] con los siguientes datos: ");
		
		String body = "Direccion ["+direccion+"] </br>  Nit ["+nit+"] </br>  Persona de Contacto ["+personaContacto+"] </br>Email ["+email+"] </br>Telefono Fijo ["+telefonoFijo+"] </br>Telefono Celular ["+telefonoCelular+"] </br>Mensaje ["+message+"] </br>" ;
		
		msgHtml = msgHtml.replaceAll("BODY_MSG", body);
		
		mail.setText(msgHtml);
		mail.setHtmlMail(true);
		
		//Miestras produccion
		mail.addRecipient(new Recipient ("javima4@gmail.com", "Recipient"));
		mail.addRecipient(new Recipient ("informacion@exprecards.com", "Recipient"));
		mail.addRecipient(new Recipient ("servicioalcliente@exprecards.com", "Recipient"));
				
		sender.send(mail);
		
		return false;
	}
   
   
   
   
   
   
   public static void main(String ar[]){
	   
  	   //MailSenderUtils.getInstance().enviarNotificacionPedidoObservacion("2031","TRAMITRADO","xxxxx  yyyyy zzzzz  ffffff  xsafd f f ","smontolla",new Date().toString());
	   float valorTotal=24567890f;
	   
	   //System.out.println(String.format("%.2f", valorTotal));
	   
	   //System.out.println(EEstadoPedido.valueOf("D").getDescripcion());
	   
	   int dia = Calendar.getInstance().getTime().getDay()+1;
	   
	   if(dia>=2 && dia<=6){
		   System.out.println("Entre semana");   
	   }
	   
	   System.out.println(Calendar.getInstance().WEDNESDAY);
	   
   }
	
	
}
